using System;
using System.Collections.Generic;
using System.Text;

namespace Common.Utilities
{
    /// <summary>
    /// 
    /// </summary>
    public class CharUtil
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="val"></param>
        /// <returns></returns>
        public static bool IsCharacter(char val)
        {
            System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex("[a-zA-Z]");
            System.Text.RegularExpressions.Match match = regex.Match(val.ToString());
            return match.Success;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="val"></param>
        /// <returns></returns>
        public static bool IsCharacter(string val)
        {
            System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex("^[a-zA-Z]+$");
            System.Text.RegularExpressions.Match match = regex.Match(val);
            return match.Success;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="val"></param>
        /// <returns></returns>
        public static bool IsCharacterOrNumber(char val)
        {
            return CharUtil.IsCharacterOrNumber(val.ToString());
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="val"></param>
        /// <returns></returns>
        public static bool IsCharacterOrNumber(string val)
        {
            System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex("^\\w+$");
            System.Text.RegularExpressions.Match match = regex.Match(val);
            return match.Success;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="val"></param>
        /// <returns></returns>
        public static bool IsNumber(string val)
        {
            System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex("^[+-]?\\d+\\.?\\d*$");
            System.Text.RegularExpressions.Match match = regex.Match(val);
            return match.Success;
        }
    }
}
